package main

import "fmt"

type BooksP struct {
	title   string
	author  string
	subject string
	book_id int
}

func main() {
	var Book1 BooksP /* 声明 Book1 为 Books 类型 */
	var Book2 BooksP /* 声明 Book2 为 Books 类型 */

	/* book 1 描述 */
	Book1.title = "Go 语言"
	Book1.author = "www.runoob.com"
	Book1.subject = "Go 语言教程"
	Book1.book_id = 6495407

	/* book 2 描述 */
	Book2.title = "Python 教程"
	Book2.author = "www.runoob.com"
	Book2.subject = "Python 语言教程"
	Book2.book_id = 6495700

	/* 打印 Book1 信息 */
	printBookP(&Book1)

	/* 打印 Book2 信息 */
	printBookP(&Book2)

	//声明一个Book3
	Book3 := Book1
	fmt.Println(Book3)
	fmt.Println(Book3.title)

	/*
		使用new创建指针类型结构体
	*/
	bkP := new(BooksP)
	bkP.title = "hello bkp"
	bkP.author = "yzb"
	fmt.Printf("%T\n", bkP)      //*main.BooksP
	fmt.Printf("bkP=%#v\n", bkP) //bkP=&main.BooksP{title:"hello bkp", author:"yzb", subject:"", book_id:0}
	fmt.Println(bkP.title)
}

//这里参数是一个结构体指针
func printBookP(book *BooksP) {
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book book_id : %d\n", book.book_id)
}
